<?php
class book extends mysql
{
	private $tablename;
	private $botable;
	private $member;
	
	public function __construct()
	{
		parent::__construct();
		$this->tablename = PREFIX . 'book';
		$this->botable   = PREFIX . 'borrow';
		$this->member    = PREFIX . 'reader';
	}

   /**
	*函数: _read_a_books()
	*功能: 读取指定id的图书
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_a_books($id)
	{
		$query = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
		  				 where `{$this->tablename}`.`bid`=%d and  `del`=0 ",  PREFIX . 'btype', PREFIX . 'btype', $id);
		if($res = $this->_select($query))
		{
			$res['pdate'] = date('Y-m-d', $res['pdate']);
			$res['indate'] = date('Y-m-d', $res['indate']);
			return $res;
		}
		else
		{
			return false;
		}
	}
	
   /**
	*函数: _read_page_books()
	*功能: 读取一页书信息
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_page_books()
	{
		global $page;		//当前页	
		$offset = ($page-1)*DISPLAY;	//数据库查询偏移量
		$query  = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
						  where `{$this->tablename}`.`del`=0 limit %d, %d", PREFIX . 'btype', PREFIX . 'btype', $offset, DISPLAY);
		if($res = $this->_selects($query))
		{
			return $res;
		}
		else
		{
			return false;
		}
	}

   /**
	*函数: _add_books($arr)
	*功能: 添加图书
	*参数: 数组
	*返回: 失败返回false
	*/
	public function _add_books($input)
	{
		if(!empty($_FILES['pic']['name']))
		{
			//上传文件
			$name     = $_FILES['pic']['name'];		//文件名
			$tmp_name = $_FILES['pic']['tmp_name'];		//服务端缓存
			$size     = $_FILES['pic']['size']; 	//文件大小
			$ext = strrchr($name, '.');				//.gif
			$ext = substr($ext, 1);					//后缀名gif
			global $allow_type;						//允许的文件类型
			list($a, $b) = explode('/', $_FILES['pic']['type']);
			$type = $a;								//上传的文件类型
			$new_filename = time() . 'upload.' . $ext;
			$path = UP_PATH . $new_filename;
			if(is_uploaded_file($tmp_name))
			{
				if($size <=MAXPOST)
				{
					if(in_array($ext, $allow_type))
					{
						if(move_uploaded_file($tmp_name, $path))
						{
							$img_path = RELATIVE_PATH . 'public/upload/' . $new_filename;
						}
						else
						{
							$this->_message('books_main.php', '上传文件失败！');
						}
					}
					else
					{
						$this->_message('books_main.php', '上传的文件类型不允许！');
					}
				}
				else
				{
					$this->_message('books_main.php', '文件不能大于' .human_size_read(MAXPOST) . '！');
				}
			}
			else
			{
				$this->_message('books_main.php', '缩略图不是上传的文件！');
			}
			if(!isset($img_path))
			{
				$img_path = '';
			}
			$input['pdate']  = strtotime($input['pdate']);
			$input['indate']  = strtotime($input['indate']);
			$query = sprintf("insert into `{$this->tablename}` 
							 (`bid`,
							 `name`,
							 `typeid`,
							 `author`,
							 `pstore`,
							 `pdate`,
							 `price`,
							 `page`,
							 `storage`,
							 `indate`,
							 `del`,
							 `times`,
							 `tuijian`,
							 `content`,
							 `pic`) values ('','%s', %d, '%s', '%s', %d, %0.2f, %d, %d, %d, 0, 0, %d, '%s', '%s')", 
							 mysql_real_escape_string($input['name']), 
							 mysql_real_escape_string($input['value']), 
							 mysql_real_escape_string($input['author']), 
							 mysql_real_escape_string($input['pstore']), 
							 mysql_real_escape_string($input['pdate']), 
							 mysql_real_escape_string($input['price']), 
							 mysql_real_escape_string($input['page']), 
							 mysql_real_escape_string($input['storage']), 
							 mysql_real_escape_string($input['indate']), 
							 mysql_real_escape_string($input['tuijian']), 
							 mysql_real_escape_string($input['content']),
							 $img_path);
		}
		else
		{
			$input['pdate']  = strtotime($input['pdate']);
			$input['indate']  = strtotime($input['indate']);
			$query = sprintf("insert into `{$this->tablename}` 
							 (`bid`,
							 `name`,
							 `typeid`,
							 `author`,
							 `pstore`,
							 `pdate`,
							 `price`,
							 `page`,
							 `storage`,
							 `indate`,
							 `del`,
							 `times`,
							 `tuijian`,
							 `content`) values ('','%s', %d, '%s', '%s', %d, %0.2f, %d, %d, %d, 0, 0, %d, '%s')", 
							 mysql_real_escape_string($input['name']), 
							 mysql_real_escape_string($input['value']), 
							 mysql_real_escape_string($input['author']), 
							 mysql_real_escape_string($input['pstore']), 
							 mysql_real_escape_string($input['pdate']), 
							 mysql_real_escape_string($input['price']), 
							 mysql_real_escape_string($input['page']), 
							 mysql_real_escape_string($input['storage']), 
							 mysql_real_escape_string($input['indate']), 
							 mysql_real_escape_string($input['tuijian']), 
							 mysql_real_escape_string($input['content']));

		}
		if($this->_insert($query))
		{
			$this->_message('books_main.php', '添加图书成功！');
		}
		else
		{
			$this->_message('books_main.php', '添加图书失败！');
		}
	}
	
   /**
	*函数: _edit_books()
	*功能: 编辑图书
	*参数: 无
	*返回: 失败返回false
	*/
	public function _edit_books($input)
	{
		if(!empty($_FILES['pic']['name']))
		{
			//上传文件
			$name     = $_FILES['pic']['name'];		//文件名
			$tmp_name = $_FILES['pic']['tmp_name'];		//服务端缓存
			$size     = $_FILES['pic']['size']; 	//文件大小
			$ext = strrchr($name, '.');				//.gif
			$ext = substr($ext, 1);					//后缀名gif
			global $allow_type;						//允许的文件类型
			list($a, $b) = explode('/', $_FILES['pic']['type']);
			$type = $a;								//上传的文件类型
			$new_filename = time() . 'upload.' . $ext;
			$path = UP_PATH . $new_filename;
			if(is_uploaded_file($tmp_name))
			{
				if($size <=MAXPOST)
				{
					if(in_array($ext, $allow_type))
					{
						if(move_uploaded_file($tmp_name, $path))
						{
							$img_path = RELATIVE_PATH . 'public/upload/' . $new_filename;
						}
						else
						{
							$this->_message('books_main.php', '上传文件失败！');
						}
					}
					else
					{
						$this->_message('books_main.php', '上传的文件类型不允许！');
					}
				}
				else
				{
					$this->_message('books_main.php', '文件不能大于' .human_size_read(MAXPOST) . '！');
				}
			}
			else
			{
				$this->_message('books_main.php', '缩略图不是上传的文件！');
			}
			if(!isset($img_path))
			{
				$img_path = '';
			}
			//文件上传成功，读取以前文件，删除它
			$del_pic = $this->_read_a_books($input['bid']);
			$del_pic = $del_pic['pic'];
			if(file_exists($del_pic))
			{
				unlink($del_pic);
			}
			$input['pdate'] = strtotime($input['pdate']);
			$query = sprintf("update `{$this->tablename}` set 
							 `name`='%s', 
							 `typeid`='%d', 
							 `author`='%s',
							 `pstore`='%s',
							 `pdate`=%d,
							 `price`='%s',
							 `page`=%d,
							 `tuijian`=%d,
							 `content`='%s',
							 `pic`='%s',
							 `storage`=%d
							 where `bid`=%d", 
							 $input['name'], 
							 $input['value'], 
							 $input['author'], 
							 $input['pstore'], 
							 $input['pdate'], 
							 $input['price'], 
							 $input['page'],
							 $input['tuijian'],
							 $input['content'],
							 $img_path,
							 $input['storage'],
							 $input['bid']);
		}
		else
		{
			$input['pdate'] = strtotime($input['pdate']);
			$query = sprintf("update `{$this->tablename}` set 
							 `name`='%s', 
							 `typeid`='%d', 
							 `author`='%s',
							 `pstore`='%s',
							 `pdate`=%d,
							 `price`='%s',
							 `page`=%d,
							 `tuijian`=%d,
							 `content`='%s',
							 `storage`=%d
							 where `bid`=%d", 
							 $input['name'], 
							 $input['value'], 
							 $input['author'], 
							 $input['pstore'], 
							 $input['pdate'], 
							 $input['price'], 
							 $input['page'],
							 $input['tuijian'],
							 $input['content'],
							 $input['storage'],
							 $input['bid']);
		}
		if($this->_update($query))
		{
			$this->_message('books_main.php', '修改成功！');
		}
		else
		{
			$this->_message('books_main.php', '未修改任何内容！');
		}
	}

   /**
	*函数: _del_books($id)
	*功能: 删除一本图书
	*参数: id
	*返回: 失败返回false
	*/
	public function _del_books($id)
	{
		$sql = "select * from `{$this->botable}` where `bookid`=" . intval($id);
		if($res = $this->_selects($sql))
		{
			$this->_message('books_main.php', '删除失败！此书正在借阅！');
		} 
		$query = sprintf("update `{$this->tablename}` set `del`=1 where `bid`=%d", $id);
		if($this->_update($query))
		{
			$this->_message('books_main.php', '删除成功！');
		}
		else
		{
			$this->_message('books_main.php', '删除失败！');
		}
	}

   /**
	*函数: _read_recyle_books()
	*功能: 读取回收站图书
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_recyle_books()
	{
		$sql = sprintf("select * from `{$this->tablename}` left join `%s` on 
						  `{$this->tablename}`.`typeid`=`%s`.`id` where `del`=1", PREFIX . 'btype', PREFIX . 'btype');
		if($res = $this->_selects($sql))
		{
			return $res;
		}
		else
		{
			return false;
		}
	}
	
   /**
	*函数: _back_books()
	*功能: 恢复回收站图书
	*参数: 无
	*返回: 失败返回false
	*/
	public function _back_books($id)
	{
		$sql = sprintf("update `{$this->tablename}` set `del`=0 where `bid`=%d", $id);
		if($this->_update($sql))
		{
			$this->_message('books_main.php?action=recyle', '还原成功！');
		}
		else
		{
			$this->_message('books_main.php?action=recyle', '还原失败！');
		}
	}

   /**
	*函数: _clean_books()
	*功能:晴空回收站图书
	*参数: 无
	*返回: 失败返回false
	*/	
	public function _clean_books($id)
	{
		$sql = sprintf("delete from `{$this->tablename}` where `bid`=%d", $id);
		$sql1 = sprintf("select `pic` from `{$this->tablename}` where `bid`=%d", $id);
		if($res = $this->_select($sql1))
		{
			if(file_exists($res['pic']))
			{
				unlink($res['pic']);	//删除图片
			}
			if($this->_delete($sql))
			{
				$this->_message('books_main.php?action=recyle', '彻底删除成功！');
			}
			else
			{
				$this->_message('books_main.php?action=recyle', '彻底删除失败！');
			}
		}
	}
	
   /**
	*函数: _read_count_books()
	*功能: 读取所有书的数目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_count_books()
	{
		$query = "select * from `{$this->tablename}` where `del`=0";
		$res = $this->_selects($query);
		return count($res);
	}

   /**
	*函数: _read_hot_books()
	*功能: 读取热门图书的数目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_hot_books()
	{
		$query  = sprintf("select * from `{$this->tablename}` left join `%s` on `del`=0 and 
						  `{$this->tablename}`.`typeid`=`%s`.`id` order by times desc  limit 0 ,10", PREFIX . 'btype', PREFIX . 'btype');
		if($res = $this->_selects($query))
		{
			return $res;
		}
		else
		{
			return false;
		}
	}
	
//----------------------------------	
   /**
	*函数: _read_class()
	*功能: 读取图书类目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_class()
	{
		$query = sprintf("select `id`,concat(fid,'-',id) as fid, value, description from `%s` order by fid", PREFIX . 'btype');
		if($res = $this->_selects($query))
		{
			foreach($res as $k=>$v)
			{
				$sql = "select * from `{$this->tablename}` where `del`=0 and `typeid`=" . $v['id'];
				$res[$k]['counts'] = count($this->_selects($sql));
				$tmp = count(explode('-', $v['fid'])) - 2;
				$pre = $tmp ? '├' . str_repeat('─', $tmp) : '';
				$res[$k]['value'] = $pre . $res[$k]['value'];
			}
			return $res;
		}	
	}

   /**
	*函数: _read_one_class()
	*功能: 读取一条图书类目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _read_one_class($id)
	{
		$sql = sprintf('select * from `%s` where `id`=%d', PREFIX . 'btype', $id);
		if($res = $this->_select($sql))
		{
			return $res;
		}
		else
		{
			return false;
		}
	}

   /**
	*函数: _add_class()
	*功能: 增加图书类目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _add_class($input)
	{
		$query = sprintf("insert into `%s` values('','%s','%s','%s', '%s')", PREFIX . 'btype', mysql_real_escape_string($input['fid']), mysql_real_escape_string($input['value']), mysql_real_escape_string($input['description']), mysql_real_escape_string($input['show']));
		if($res = $this->_insert($query))
		{
			$this->_message('books_class.php', '成功增加了一个子类！ID：' . $res);
		}
	}
	
   /**
	*函数: _edit_class()
	*功能: 编辑图书类目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _edit_class($input)
	{
		$query = sprintf("update `%s` set `value`='%s', `description`='%s', `show` = '%s' where `id`=%d", 
						  PREFIX . 'btype', mysql_real_escape_string($input['value']), 
						  mysql_real_escape_string($input['description']),
						  mysql_real_escape_string($input['show']),
						  mysql_real_escape_string($input['id']));
		if($this->_update($query))
		{
			$this->_message('books_class.php', '修改成功！');
		}
		else
		{
			
		}
	}
	
   /**
	*函数: _del_class()
	*功能: 删除图书类目
	*参数: 无
	*返回: 失败返回false
	*/
	public function _del_class($id, $fid)
	{
		$query = sprintf('select * from `%s` where `fid` like \'%s%%\'', PREFIX . 'btype', $fid);
		if($res = $this->_select($query))
		{
			$this->_message('books_class.php', '删除失败！此类含有子类！请先删除子类！');
		}
		else
		{
			$query2 = sprintf("select `bid` from `{$this->tablename}` where `typeid`=%d", $id);
			if($res2 = $this->_select($query2))
			{
				$this->_message('books_class.php', '删除失败！此类含有图书！请先删除其类下图书！');
			}
			else
			{
				$sql = sprintf("delete from `%s` where `id`=%d", PREFIX . 'btype', $id);
				if($this->_delete($sql))
				{
					$this->_message('books_class.php', '删除成功！');
				}
			}
		}
	}
	
//------------------------------------------图书借阅-------------------
   /**
	*函数: bo_allnum()
	*功能: 读出所有借出的书的数目
	*参数: 无
	*返回: 失败返回false
	*/
	public function bo_allnum()
	{
		$sql = "select * from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=0 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid`";
		if($res = $this->_selects($sql))
		{
			return count($res);
		}
		else
		{
			return false;
		}
	}
	
   /**
	*函数: bo_all()
	*功能: 读出所有借出的书
	*参数: 无
	*返回: 失败返回false
	*/
	public function bo_all()
	{
		global $page;		//当前页	
		$offset = ($page-1)*DISPLAY;	//数据库查询偏移量
		$query = "select * from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=0 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid` limit {$offset}," . DISPLAY;
		if($res = $this->_selects($query))
		{
			$num = count($res);
			for($i = 0; $i <$num; $i++)
			{
				if($res[$i]['goon'] == 1)
				{
					$res[$i]['goon'] = '<font color="#FF0000">已续借</font>';
				}
				else
				{
					$res[$i]['goon'] = '<font color="#00CC00">未续借</a>';
				}
				if($res[$i]['isback'] == 1)
				{
					$res[$i]['isback'] = '<font color="#00CC00">已归还</font>';
				}
				else
				{
					$res[$i]['isback'] = '<font color="#FF0000">未归还</font>';
				}
				$res[$i]['borrowdate'] = d($res[$i]['borrowdate']);	//借出时间
				$res[$i]['backdate'] = d($res[$i]['backdate']); 	//应还时间
			}
			return $res;
		}
	}
	
   /**
	*函数: bo_backnum()
	*功能: 读出所有已还书的数目
	*参数: 无
	*返回: 失败返回false
	*/
	public function bo_backnum()
	{
		$sql = "select * from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=1 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid`";
		if($res = $this->_selects($sql))
		{
			return count($res);
		}
		else
		{
			return false;
		}
	}


   /**
	*函数: bo_users()
	*功能: 读出所有用户现在在借的书
	*参数: 无
	*返回: 失败返回false
	*/
	public function bo_users($id)
	{
		$query = sprintf("select * from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=0 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid` and `{$this->botable}`.`readerid`=%d", $id);
		if($res = $this->_selects($query))
		{
			$num = count($res);
			for($i = 0; $i <$num; $i++)
			{
				if($res[$i]['goon'] == 1)
				{
					$res[$i]['goon'] = '<font color="#FF0000">已续借</font>';
				}
				else
				{
					$res[$i]['goon'] = '<font color="#00CC00">未续借</a>';
				}
				if($res[$i]['isback'] == 1)
				{
					$res[$i]['isback'] = '<font color="#00CC00">已归还</font>';
				}
				else
				{
					$res[$i]['isback'] = '<font color="#FF0000">未归还</font>';
				}
				$res[$i]['borrowdate'] = d($res[$i]['borrowdate']);	//借出时间
				$res[$i]['backdate'] = d($res[$i]['backdate']); 	//应还时间
			}
			return $res;
		}
	}

   /**
	*函数: _get_guoqi($userid)
	*功能: 读取过期未归还的图书)
	*参数: $arr
	*返回: 失败返回false
	*/
	public function _get_guoqi()
	{
		global $page;					//当前页	
		$offset = ($page-1)*DISPLAY;	//数据库查询偏移量
		$query = "select * from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=0 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid` and 
				 `{$this->botable}`.`backdate`<" . time() . "  limit {$offset}," . DISPLAY;
		if($res = $this->_selects($query))
		{
			$num = count($res);
			for($i = 0; $i <$num; $i++)
			{
				if($res[$i]['goon'] == 1)
				{
					$res[$i]['goon'] = '<font color="#FF0000">已续借</font>';
				}
				else
				{
					$res[$i]['goon'] = '<font color="#00CC00">未续借</a>';
				}
				if($res[$i]['isback'] == 1)
				{
					$res[$i]['isback'] = '<font color="#00CC00">已归还</font>';
				}
				else
				{
					$res[$i]['isback'] = '<font color="#FF0000">未归还</font>';
				}
				$res[$i]['borrowdate'] = d($res[$i]['borrowdate']);	//借出时间
				$res[$i]['backdate'] = d($res[$i]['backdate']); 	//应还时间
			}
			return $res;
		}
	}
	
   /**
    * 读取过期图书数量
	*/
	public function _get_guoqi_num()
	{
		$sql = "select count(*) as num from `{$this->botable}`,`{$this->tablename}`,`{$this->member}` 
				 where `{$this->botable}`.`isback`=0 and 
				 `{$this->tablename}`.`bid`=`{$this->botable}`.`bookid` and
				 `{$this->member}`.`id`=`{$this->botable}`.`readerid` and 
				 `{$this->botable}`.`backdate`<" . time();
		$res = $this->_select($sql);
		return $res['num'];
	}
	
   /**
	*函数: _search_book($arr)
	*功能: 搜索图书
	*参数: $arr
	*返回: 失败返回false
	*/
	public function _search_book($arr)
	{
		if(trim($arr['search_book']) == '' || trim($arr['search_book']) == '搜索')
		{
			$this->_message('books_main.php', '请输入搜索的关键字');
		}
		switch($arr['title'])
		{
			case 'name':
				$query  = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
						  where `{$this->tablename}`.`del`=0 and 
						  `{$this->tablename}`.`name` like '%%%s%%'", 
						  PREFIX . 'btype', PREFIX . 'btype', mysql_real_escape_string(trim($arr['search_book'])));
				$rep = 'name';
				break;
			case 'pstore':
				$query  = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
						  where `{$this->tablename}`.`del`=0 and 
						  `{$this->tablename}`.`pstore` like '%%%s%%'", 
						  PREFIX . 'btype', PREFIX . 'btype', mysql_real_escape_string(trim($arr['search_book'])));
				$rep = 'pstore';
				break;
			case 'author':
				$query  = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
					  where `{$this->tablename}`.`del`=0 and 
					  `{$this->tablename}`.`author` like '%%%s%%'", 
					  PREFIX . 'btype', PREFIX . 'btype', mysql_real_escape_string(trim($arr['search_book'])));
				$rep = 'author';
				break;
			case 'type':
				$query = sprintf("select * from `{$this->tablename}` left join `%s` on `{$this->tablename}`.`typeid`=`%s`.`id` 
					  where `{$this->tablename}`.`del`=0 and 
					  `%s`.`value` like '%%%s%%'", 
					  PREFIX . 'btype', PREFIX . 'btype', PREFIX . 'btype', mysql_real_escape_string(trim($arr['search_book'])));
				$rep = 'value';
				break;
		}
		if($res = $this->_selects($query))
		{
			foreach($res as $key=>$val)
			{
				$ser = trim($arr['search_book']);
				if($new = preg_replace("/($ser)/i", '<font color="red">\\1</font>', $val[$rep]))
				{
					$res[$key][$rep] = $new;
				}
			}
			return $res;
		}
		else
		{
			return false;
		}
	}

   /**
	*函数: _class_by_pstore()
	*功能: 根据出版社读取图书
	*参数: 
	*返回: 失败返回false
	*/
	public function _class_by_pstore()
	{
		$sql = "select distinct `pstore` from `{$this->tablename}` where `del`=0";	//查询所有出版社
		if($res = $this->_selects($sql))
		{
			foreach($res as $k=>$v)
			{
				$query = "select * from `{$this->tablename}` where `pstore`= '" . $v['pstore'] . "'";
				if($num = $this->_num_rows($query))
				{
					$res[$k]['num'] = $num;
				}
			}
		}
		return $res;
	}

   /**
	*函数: _class_by_date()
	*功能: 根据出版日期读取图书
	*参数: 
	*返回: 失败返回false
	*/
	public function _class_by_date()
	{
		$arr   = array();
		$now   = time();
		$one   = time() - 12*30*24*60*60;
		$two   = time() - 24*30*24*60*60;
		$three = time() - 36*30*24*60*60;
		$four  = time() - 48*30*24*60*60;
		$five  = time() - 60*30*24*60*60;
		$ten   = 1;
		$date_arr = compact('now', 'one', 'two', 'three', 'four', 'five', 'ten');		//数组键名为变量名，值为变量值
		sort($date_arr);																//数字索引排序
		$size = count($date_arr);
		for($i = $size; $i >0; $i--)
		{
			$sql  = sprintf("select * from `{$this->tablename}` where `del`=0 and 
					   `pdate` between %d and %d order by `pdate` desc", 
					   $date_arr[$i-1], $date_arr[$i]);
			if($res = $this->_num_rows($sql))
			{
				$arr[$size - $i] = $res;
			}
			else
			{
				$arr[$size - $i] = 0;
			}
		}
		return $arr;
	}
//-------------------------class end ----------------------------------	
}
?>